<?php 
    session_start();
    echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];
    echo "<br/>Welcome ".$_COOKIE["username"];
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        
            <link rel="stylesheet" href="styles/layout.css" type="text/css"/>
            <link rel="stylesheet" href="styles/computer.css" type="text/css"/>
            <script type="text/javascript" src="scripts/computer.js"></script>
        
        <script type="text/javascript">
            var xmlhttp;
            
            function showProduct(){
//                alert("zhouzhao");
                var productName = document.product.productName.value;
                var categoryID = document.product.categoryID.value;
                var minPrice = document.product.minPrice.value;
                var maxPrice = document.product.maxPrice.value;
                
//               alert(productName);
                
                if(window.XMLHttpRequest){
                    //code for IE7+, Firefox, Chrome, and Safari
                    xmlhttp = new XMLHttpRequest();
                }else{
                    //code for IE6 and IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                
                xmlhttp.onreadystatechange = handleReplyProduct;
                xmlhttp.open("GET", "showProduct.php?productName="+productName+"&categoryID="+categoryID+"&minPrice="+minPrice+"&maxPrice="+maxPrice, true);
                xmlhttp.send();
            }
            
            function handleReplyProduct(){
                if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//                    alert(xmlhttp.responseText);
                    document.getElementById("productResult").innerHTML = xmlhttp.responseText;
                }
            }
            
            function showUser(userType){
                
                if(window.XMLHttpRequest){
                    //code for IE7+, Firefox, Chrome, and Safari
                    xmlhttp = new XMLHttpRequest();
                }else{
                    //code for IE6 and IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                
                xmlhttp.onreadystatechange = handleReplyUser;
                xmlhttp.open("GET", "showUser.php?userType="+userType, true);
                xmlhttp.send();
            }
            
            function handleReplyUser(){
                if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//                    alert(xmlhttp.responseText);
                    document.getElementById("userResult").innerHTML = xmlhttp.responseText;
                }
            }
            
            function showSale(){
                
                var productName = document.sale.productName.value;
                var categoryID = document.sale.categoryID.value;
                var minPrice = document.sale.minPrice.value;
                var maxPrice = document.sale.maxPrice.value;
                var startDate = document.sale.startDate.value;
                var endDate = document.sale.endDate.value;
                
                if(window.XMLHttpRequest){
                    //code for IE7+, Firefox, Chrome, and Safari
                    xmlhttp = new XMLHttpRequest();
                }else{
                    //code for IE6 and IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                
                xmlhttp.onreadystatechange = handleReplySale;
                xmlhttp.open("GET", "showSale.php?productName="+productName+"&categoryID="+categoryID+"&minPrice="+minPrice+"&maxPrice="+maxPrice+"&startDate="+startDate+"&endDate="+endDate, true);
                xmlhttp.send();                
            }
            
            function handleReplySale(){
               if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//                    alert(xmlhttp.responseText);
                    document.getElementById("saleResult").innerHTML = xmlhttp.responseText;
                }                
            }
            
            function showCategory(){
                var categoryName = document.category.categoryName.value;
                
                if(window.XMLHttpRequest){
                    //code for IE7+, Firefox, Chrome, and Safari
                    xmlhttp = new XMLHttpRequest();
                }else{
                    //code for IE6 and IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                
                xmlhttp.onreadystatechange = handleReplyCategory;
                xmlhttp.open("GET", "showCategory.php?categoryName="+categoryName, true);
                xmlhttp.send();                
            }
            
            function handleReplyCategory(){
               if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//                    alert(xmlhttp.responseText);
                    document.getElementById("categoryResult").innerHTML = xmlhttp.responseText;
                }                 
            }
            
            function showOrder(){
               var productName = document.order.productName.value;
               var categoryID = document.order.categoryID.value;
               var startDate = document.order.startDate.value;
               var endDate = document.order.endDate.value;
               
               if(window.XMLHttpRequest){
                    //code for IE7+, Firefox, Chrome, and Safari
                    xmlhttp = new XMLHttpRequest();
                }else{
                    //code for IE6 and IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                
                xmlhttp.onreadystatechange = handleReplyOrder;
                xmlhttp.open("GET", "showOrderManager.php?productName="+productName+"&categoryID="+categoryID+"&startDate="+startDate+"&endDate="+endDate, true);
                xmlhttp.send();                
            }
            
            function handleReplyOrder(){
               if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//                    alert(xmlhttp.responseText);
                    document.getElementById("orderResult").innerHTML = xmlhttp.responseText;
                }                
            }
            
        </script>
        
    </head>
    <body>
        <?php
        require 'header.html';
        ?>
<div id="container">
<div class="wrapper">
<div id="content">
<div id="order">        
        <?php
        // put your code here
        if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "manager")){
        ?>
        
        <form name="product">
            <p>Product name: <input type="text" name="productName" maxlength="20" class="rightAlign"/></p>
            <p>Product category: <input type="text" name="categoryID" maxlength="20" class="rightAlign"/></p>
            <p>Product min price: <input type="text" name="minPrice" maxlength="10" class="rightAlign"/></p>
            <p>Product max price: <input type="text" name="maxPrice" maxlength="10" class="rightAlign"/></p>
            <input type="button" value="Search product" onclick="showProduct()" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form><br/>
        <div id="productResult"><b>Product result will be listed here ...</b></div><br/>
        
        <form name="user">
            <select name="userType" onchange="showUser(this.value)">
                <option value="all">All</option>
                <option value="administrator">Administrator</option>
                <option value="seller">Seller</option>
                <option value="manager">Manager</option>
            </select> 
        </form><br/>
        <div id="userResult"><b>User result will be listed here ...</b></div><br/>
        
        <form name="sale">
            <p>Product name: <input type="text" name="productName" maxlength="20" class="rightAlign"/></p>
            <p>Product category: <input type="text" name="categoryID" maxlength="20" class="rightAlign"/></p>
            <p>Sale start date: <input type="text" name="startDate" maxlength="20" class="rightAlign"/></p>
            <p>Sale end date: <input type="text" name="endDate" maxlength="20" class="rightAlign"/></p>
            <p>Product min price: <input type="text" name="minPrice" maxlength="10" class="rightAlign"/></p>
            <p>Product max price: <input type="text" name="maxPrice" maxlength="10" class="rightAlign"/></p>
            <input type="button" value="Search sale" onclick="showSale()" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form><br/>
        <div id="saleResult"><b>Sale result will be listed here ...</b></div><br/>
        
        <form name="category">
            <p>Category name: <input type="text" name="categoryName" maxlength="20" class="rightAlign"/></p>
            <input type="button" value="Search category" onclick="showCategory()" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form><br/>
        <div id="categoryResult"><b>Category result will be listed here ...</b></div>
        
        <form name="order">
            <p>Product name: <input type="text" name="productName" maxlength="20" class="rightAlign"/></p>
            <p>Product category: <input type="text" name="categoryID" maxlength="20" class="rightAlign"/></p>
            <p>Order start date: <input type="text" name="startDate" maxlength="20" class="rightAlign"/></p>
            <p>Order end date: <input type="text" name="endDate" maxlength="20" class="rightAlign"/></p>
            <input type="button" value="Search order" onclick="showOrder()" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form>
        <div id="orderResult"><b>Order result will be listed here ...</b></div>
        
        <?php
        }else{
            /*Managers get new reports to see all about orders. They are to be able to retrieve orders, and summaries of product sold by date, by product category, by special sales items, or by product. Note: A single request could provide values for all three organizing ways. For example, a manager wants the total sales for a specific product category, for a specific time frame they specify. */
            
            require 'login.html';
        }
        ?>
</div>	
</div>
<br class="clear" />
</div>
</div>
        <?php
        require 'tail.html';
        ?>
    </body>
</html>
